/**
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 *
 *DutyRecordController
 * 值班人员记录表
 *
 * 修改纪录
 * 2021-06-03 版本：1.0 chengengwei 创建。
 * @version 版本：1.0
 * @author 作者：chengengwei
 * 创建日期：2021-06-03
 */

package com.topscomm.duty.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.topscomm.cbo.pojo.CboDeptEntity;
import com.topscomm.cbo.service.ICboDeptService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.topscomm.duty.controller.auto.DutyRecordControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: chengengwei
 * @date: 2021-06-03
 * @description:值班人员记录表Controller
 * @modify:
 */
@RestController
@RequestMapping("duty/record")
public class DutyRecordController extends DutyRecordControllerAuto implements IDutyRecordController {

	@Autowired
	private ICboDeptService cboDeptService;

	/**
	 * @author: chengengwei
	 * @date: 2021-06-03
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: chengengwei
	 * @date: 2021-06-03
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * @description:值班列表查询
	 * @author: chengengwei
	 * @date: 2021-06-03
	 * @modify:
	 */
	@GetMapping(value = "/queryOnDutyList")
	public ResponseResult<Object> queryOnDutyList(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			Map<String, Object> resultMap = new HashMap<>();
			this.service.queryOnDutyList(paraMap, resultMap);
			return ResponseResult.ok(resultMap);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}

	/**
	 * @description:值班表提交
	 * @author: chengengwei
	 * @date: 2021-06-04
	 * @modify:
	 */
	@PostMapping(value = "/submitOnDutyList")
	public ResponseResult<Object> submitOnDutyList(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			this.service.submitOnDutyList(paraMap, this.getUserBean());
			return ResponseResult.ok("提交成功");
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}

	/**
	 * @description:根据CHO查询值班记录
	 * @author: chengengwei
	 * @date: 2021-06-05
	 * @modify:
	 */
	@GetMapping(value = "/queryOnDutyListByCHO")
	public ResponseResult<Object> queryOnDutyListByCHO(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			Map<String, Object> resultMap = new HashMap<>();
			this.service.queryOnDutyListByCHO(paraMap, resultMap, this.getUserBean());
			return ResponseResult.ok(resultMap);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}

	/**
	 * @description:判断当前用户是否为CHO
	 * @author: chengengwei
	 * @date: 2021-06-05
	 * @modify:
	 */
	@GetMapping(value = "/judgeIsCHO")
	public ResponseResult<Object> judgeIsCHO(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			Map<String, Object> resultMap = new HashMap<>();
			this.service.judgeIsCHO(resultMap, this.getUserBean());
			return ResponseResult.ok(resultMap);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}
}

